/*
 * @(#)ElementNode.java   09/09/13
 *
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 *
 *
 *
 */



package fr.ema.arch3d.gea.mainGUI.TreeTable;

import fr.ema.arch3d.model.architecture.Interface;
import fr.ema.arch3d.model.architecture.specification.ComponentRole;
import fr.ema.arch3d.model.architecture.specification.Specification;

import org.objectweb.fractal.api.type.InterfaceType;

import java.util.List;

import javax.swing.tree.DefaultMutableTreeNode;

/**
 * Class description
 *
 *
 * @version        1.0, 09/09/13
 * @author         Huaxi (Yulin) ZHANG
 */
class ElementNode extends DefaultMutableTreeNode {

    /** Field description */
    String value;

    /**
     * Constructs ...
     *
     *
     * @param cr
     */
    public ElementNode(ComponentRole cr) {
        Interface[] itfs    = cr.getInterfaces();
        ElementNode itfNode = new ElementNode("Interfaces", null);

        for (int i = 0; i < itfs.length; i++) {
            itfNode.add(new ElementNode(itfs[i]));
        }

        this.add(itfNode);
        this.setUserObject("Component Role : " + cr.getName());
        this.add(new ElementNode("Bhavior", cr.getBehavior()));
    }

    /**
     * Constructs ...
     *
     *
     * @param itf
     */
    public ElementNode(Interface itf) {
        this.setUserObject("Interface : " + itf.getFcItfName());

        ElementNode signature = new ElementNode("Signature", itf.getFcItfSignature());
        ElementNode role;

        if (itf.isFcClientItf()) {
            role = new ElementNode("Role", "client");
        } else {
            role = new ElementNode("Role", "server");
        }

        this.add(signature);
        this.add(role);
    }

    /**
     *
     * @param spec get the tree of specification
     */
    public ElementNode(Specification spec) {
        this.setUserObject("Specfication : " + spec.getName());

        ElementNode crs = new ElementNode("Component Roles", null);

        this.add(crs);

        for (int i = 0; i < spec.getCmpRoleList().size(); i++) {
            crs.add(new ElementNode((ComponentRole) spec.getCmpRoleList().get(i)));
        }
    }

    /**
     * Constructs ...
     *
     *
     * @param compositeNode
     * @param value
     */
    public ElementNode(String compositeNode, String value) {
        this.value = value;
        this.setUserObject(compositeNode);
    }

    public String getValue() {
        return value;
    }
}
